package com.xnyzc.lhy.didi.Impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.didi.entity.order.OaSysCityInfo;
import com.xnyzc.lhy.didi.mapper.price.OaSysCityInfoMapper;
import com.xnyzc.lhy.didi.service.cityInfo.CityInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class CityInfoServiceImpl implements CityInfoService {
    @Autowired
    private OaSysCityInfoMapper oaSysCityInfoMapper;
    @Autowired
    private RedisCommon redisCommon;

    @Override
    public void refreshCityInfo() {
        List<OaSysCityInfo> oaSysCityInfos = oaSysCityInfoMapper.selectList(new QueryWrapper<>());
        List<String> cityInfoStrs = new ArrayList<>();
        for (int i = 0; i < oaSysCityInfos.size(); i++) {
            cityInfoStrs.add(JSON.toJSONString(oaSysCityInfos.get(i)));
        }
        redisCommon.remove(RedisPrefixConstant.CITY_CENTER_POINTS);
        redisCommon.setList(RedisPrefixConstant.CITY_CENTER_POINTS, cityInfoStrs);
        log.info("城市中心区域写入redis完毕，共写入{}条。", oaSysCityInfos.size());
    }
}
